package com.kreedx.article.factory;

import com.kreedx.article.factory.repository.ArticleRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import javax.annotation.Resource;

@Slf4j
@SpringBootApplication
@ComponentScan(value = {"com.geccocrawler.gecco.spring", "com.kreedx.article.factory"})
public class FactoryApplication implements ApplicationRunner {
    public static void main(String[] args) {
        SpringApplication.run(FactoryApplication.class, args);
    }

    @Resource
    ArticleRepository articleRepository;

    @Override
    public void run(ApplicationArguments args) throws Exception {
//        Article article = new Article();
//        article.setTitle("测试120");
//        article.setContent("我是测试内容，by kreedx");
//        article.setCreateAt(new Date());
////        articleRepository.save(article);
////        Page<Article> articlePage = articleRepository.searchSimilar(article, new String[]{"title"}, PageRequest.of(0, 10));

////        articlePage.getContent().forEach(article1 -> {
////            articleRepository.delete(article1);
////        });

//        articleRepository.deleteAll();

//        Page<Article> articlePage = articleRepository.findByTitleLike("天问一号",PageRequest.of(0, 10, Sort.by("createAt").ascending()));
//        log.info(JSON.toJSONString(articlePage.getContent().stream().map(Article::getId).collect(Collectors.toList())));

    }
}
